
NUI Chapter 6.5. Topcodes and the Robot Arm

From the website:

  Killer Game Programming in Java
  http://fivedots.coe.psu.ac.th/~ad/jg

  Dr. Andrew Davison
  Dept. of Computer Engineering
  Prince of Songkla University
  Hat yai, Songkhla 90112, Thailand
  E-mail: ad@fivedots.coe.psu.ac.th


If you use this code, please mention my name, and include a link
to the website.

Thanks,
  Andrew

============================
FIRST...
You should get the robot arm working by following the steps described in
Chapter 6 (http://fivedots.coe.psu.ac.th/~ad/jg/nui06/). 
============================


This directory contains 11 Java files:
  * TCRobotArm.java, TCPanel.java, JMFCapture.java,
    Landmarks.java, Trackers.java, TopCodeItem.java,
    RobotArm.java, Joint.java, ArmCommunicator.java,
    Coord3D.java, JointID.java


One configuration file for the topcode landmarks 
(I've used IDs 333, 283, and 211):
  * landmarks.txt


There 4 arm configuration files, used by the application:
  * baseJI.txt, shoulderJI.txt, 
    elbowJI.txt, wristJI.txt


There are 2 batch files:
  * compile.bat
  * run.bat
     - make sure they refer to the correct locations for all 
       the many, many libraries


----------------------------
Before Compilation/Execution:


You need to download and install:

   * libusb-win32: http://sourceforge.net/apps/trac/libusb-win32/wiki
             I downloaded libusb-win32-bin-1.2.4.0.zip
             --> The executable installs libusb-win32 into c:\Program Files\LibUSB-Win32\
             --> copy and rename the relevant DLLs in bin\ over to the OS
                   e.g. libusb0_x86.dll --> Windows\system32\libusb0.dll 
                        libusb0.sys --> Windows\systems32\drivers\libusb0.sys

   * libusbjava: http://libusbjava.sourceforge.net/wp/
             I downloaded ch.ntb.usb-0.5.9.jar and LibusbJava_dll_0.2.4.0.zip
             --> move the JAR and unzipped DLL to c:\LibUsbJava

   * JMF: http://java.sun.com/products/java-media/jmf/
          I downloaded the JMF Performance Pack for Windows v.2.1.1e 
          and installed it in C:\Program Files\JMF2.1.1e
 
   * OpenCV: http://opencv.willowgarage.com/
             I downloaded v2.2 for Windows with pre-compiled binaries:
                OpenCV-2.2.0-win32-vs2010.exe
             and installed it in C:\OpenCV2.2

   * JavaCV: http://code.google.com/p/javacv/
             I downloaded javacv-bin-20110219.zip 
                      and javacv-src-20110219.zip
              --> I unzipped the 'bin' file and installed it in C:\javacv-bin
              --> I unzipped the 'src' file so I could search the source code
                  and generate Java docs

   * topCodes: http://users.eecs.northwestern.edu/~mhorn/topcodes/
               I downloaded http://users.eecs.northwestern.edu/~mhorn/topcodes/topcodes.zip
               --> I unzipped it to D:\topcodes\
               --> for testing see the "Quick Start Guide" at the topcodes website

----------------------------
Other requirements:

  * obtain a OWI-535 robot arm 
   (http://www.owirobot.com/products/Robotic-Arm-Edge.html), 
    **and** its USB interface.
      ^^^
    I obtained mine from Maplin Electronics
       http://www.maplin.co.uk/robotic-arm-kit-with-usb-pc-interface-266257

    Most online electronic hobbyist sites stock the bundle
    e.g. Planet Robotic 
       http://www.planetrobotic.com/content/
                         robotic-arm-edge-bundle-owi-535-kit-and-usb-interface

  * The driver software may not include a Windows 7 version, but the 
    OWI Robotics website has drivers at 
      http://www.owirobot.com/pages/Downloads.html

  * install the arm's ELAN USB driver

  * Create a libusb-win32 device driver for the ELAN driver using 
    libusb-win32's inf-wizard.exe

  * a webcam and a tripod (see the pictures at the start of the chapter for
     how they should be positioned)

  * a sheet of topcodes graphics from 
    http://users.eecs.northwestern.edu/~mhorn/topcodes/topcodes.pdf
      --> print out the topcodes for IDs 205, 211, 283, 327, and 333
           - I use these in my code  

----------------------------
Setting up the Robot's Work Area

1. You'll need something for the robot to grab. I used a bit of sponge
cut out of a washpad for cleaning dishes. Make it
about 7-8cm high, with a narrow top but wider base.
   -- stick the topcode ID 205 to its top

2. A large sheet of graph paper marked in centimeters. The base of the arm,
directly below the shoulder gear, should be placed at (0,0).

Right of the base is the +x axis, left is -x, and forwards is the +y axis

I drew the graph paper myself: a grid at 5cm intervals.

  -- stick the topcode IDs for 211, 283 and 333 at locations that match those
     in the landmarks.txt file
  -- the final topcode, ID 327, can be placed anywhere on the grid; don't stick
     it down

----------------------------
Compilation:

> compile *.java
    // you must have all the many, many libraries installed

----------------------------
Execution:

Before you start:
    - you must have all the many, many libraries installed
    - you must have installed a libusb driver for the robot arm;
    - you must plug in the robot arm 
    - you must plug in the webcam, and have previously set it 
      up with JMF (see below for details)


> run TCRobotArm
    - when you press the "Move Item" button, the arm will pick up the sponge
      and move it to the location of topcode ID 327


The capture device must be registered with "JMF Registry"
before TCRobotArm will see it. You'll find the application below 
the JMF menu item in Windows.  

Check the device name using "JMF Registry", and update the 
CAP_DEVICE string in JMFCapture.java accordingly. Currently it
has the value: "vfw:Microsoft WDM Image Capture (Win32):0",
which is a commonly used name in WinXP.

On my test machine, it sometimes takes 5 seconds for the first
picture to appear, but only 10-20ms for each subsequent one.

The application 'freezes' for a few seconds when the application's
close box is pressed, to wait for the JMF link to be completely
shut down.

----------------------------
Last updated: 24th July 2011
